package org.lhz;

import org.lhz.entity.BunsBusCar;
import org.lhz.service.BunsCarMessageService;
import org.lhz.service.impl.BunsCarMessageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/index")
public class IndexController extends HttpServlet {
    //注入service层对象
    private BunsCarMessageService bunsCarMessageService = new BunsCarMessageServiceImpl();


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置字符编码
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        //查询所有的车类型
        List<BunsBusCar> carType = bunsCarMessageService.findCarType();
        //查询所有的车辆信息
        List<BunsBusCar> busCars = bunsCarMessageService.loadAll(null);
        //输出数据，将数据放到请求作用域中
        req.setAttribute("carType",carType);
        req.setAttribute("carList",busCars);
        //请求转发到本页
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }
}
